package com.seocoo.worker.order.model;


import com.seocoo.worker.base.http.BasePageRsp;
import com.seocoo.worker.friend.entity.RxRefreshSuccess;
import com.seocoo.worker.order.entity.RspOrderInstall;
import com.seocoo.worker.order.entity.RxCancelInstallSuccess;
import com.seocoo.worker.order.req.ReqAppointmentTime;
import com.seocoo.worker.order.req.ReqOrderInstall;
import com.seocoo.worker.order.req.ReqPackUpOrder;
import com.seocoo.worker.order.req.ReqTakeInstallOrder;
import com.sfh.lib.HandleException;
import com.sfh.lib.IResult;
import com.sfh.lib.event.BusEventManager;
import com.sfh.lib.mvvm.BaseViewModel;

/**
 * author : Ssp
 * e-mail : 981297079@qq.com
 * date   : 2020/2/2320:32
 * desc   : 安装订单列表
 * version: 1.0
 */
public class OrderInstallModel extends BaseViewModel {

    public void refreshData(ReqOrderInstall reqOrderInstall) {
        this.execute(reqOrderInstall, new IResult<BasePageRsp<RspOrderInstall>>() {
            @Override
            public void onFail(HandleException e) {
                setValue("onQueryError");
            }

            @Override
            public void onSuccess(BasePageRsp<RspOrderInstall> t) throws Exception {
                setValue("onQuerySuccess", t);
            }
        });
    }

    public void takeInstallOrder(String orderId) {
        this.execute(true, new ReqTakeInstallOrder(orderId), t -> {
            hideLoading();
            if (t.success()) {
                showToast(t.getMsg());
                setValue("onTakeSuccess");
            } else {
                showDialogToast(t.getMsg());
            }
        });
    }

    public void packUpOrder(String orderId) {
        this.execute(true, new ReqPackUpOrder(orderId), t -> {
            hideLoading();
            if (t.success()) {
                showToast(t.getMsg());
                setValue("onTakeSuccess");
            } else {
                showDialogToast(t.getMsg());
            }
        });
    }

    public void appointmentTimeOrder(ReqAppointmentTime req) {
        this.execute(true, req, t -> {
            hideLoading();
            if (t.success()) {
                showToast(t.getMsg());
                setValue("onTakeSuccess");
            } else {
                showDialogToast(t.getMsg());
            }
        });
    }
}
